package org.hbnu.xiaomi.mapper;

import org.apache.ibatis.annotations.*;
import org.hbnu.xiaomi.entity.Users;

import java.util.List;

//用户数据对象查询接口
@Mapper
public interface UsersMapper {
    // 添加用户
    @Insert("INSERT INTO users(email, password, nickname, age, sex, phone, address) " +
            "VALUES(#{email}, #{password}, #{nickname}, #{age}, #{sex}, #{phone}, #{address})")
    void addUser(Users user);

    @Select("select  * from users where id=#{id}")
    public Users getById(int id);

    // 根据邮箱查询用户
    @Select("SELECT * FROM users WHERE email = #{email}")
    Users getUserByEmail(String email);

    //根据用户id查找用户的nickname
    @Select("SELECT nickname FROM users WHERE id = #{id}")
    String findNicknameById(int id);

    // 查询所有用户
    @Select("SELECT * FROM users")
    List<Users> getAllUsers();

    // 更新用户信息
    @Update("UPDATE users SET email = #{email}, password = #{password}, nickname = #{nickname}, " +
            "age = #{age}, sex = #{sex}, phone = #{phone}, address = #{address} WHERE id = #{id}")
    void updateUser(Users user);

    // 删除用户
    @Delete("DELETE FROM users WHERE id = #{id}")
    void deleteUser(int id);

}
